Page({
  data: {
    title: "格林篮球馆",//标题
    date: '',
    show: false,//日历
    timeInfo: [
      {
        time: "2021-12-01",
        day: "周三",
        image: "../../image/duihao.png"
      },
      {
        time: "2021-12-02",
        day: "周四",
        image: "../../image/duihao.png"
      }
    ],//日期
    activeIndex: -1,//日期初始值
    fieldIndex: -1,//领域初始值
    timeIndex: -1,//时间初始值
    fieldList: [
      {
        title: "一号半场",
        image: "../../image/duihao.png"
      },
      {
        title: "二号半场",
        image: "../../image/duihao.png"
      },
    ],//场地列表
    timeList: [
      {
        time: "10:00-11:00",
        image: "../../image/duihao.png"
      },
      {
        time: "11:00-12:00",
        image: "../../image/duihao.png"
      },
      {
        time: "12:00-13:00",
        image: "../../image/duihao.png"
      },
      {
        time: "13:00-14:00",
        image: "../../image/duihao.png"
      },
      {
        time: "14:00-15:00",
        image: "../../image/duihao.png"
      },
      {
        time: "15:00-16:00",
        image: "../../image/duihao.png"
      },
      {
        time: "16:00-17:00",
        image: "../../image/duihao.png"
      },
    ]
  },
  onShow() {
    let date = new Date()
    let year = date.getFullYear()//年份
    console.log(year);
    let month = date.getMonth() + 1//月份
    console.log(month);
    let day = date.getDate()//日
    console.log(day);
    let week = date.getDay()//周几
    console.log(week);
    for (var i = 0; i < 2; i++) {

    }
  },
  //返回上一个页面
  return() {
    wx.navigateBack({
      delta: 1,
    })
  },
  // 点击跳转到确定订单页面
  toConfrim() {
    if (this.data.activeIndex == -1 || this.data.fieldIndex == -1 || this.data.timeIndex == -1) {
      wx.showToast({
        title: '请选择详细的信息',
        icon: "none"
      })
      return
    } else {
      wx.navigateTo({
        url: '../confirm/confirm?data='+this.date+"&day="+this.day+"&fiel="+this.fiel+"&time="+this.time,
      })
    }
  },
  //点击更多日期 弹出日历
  moreTime(e) {
    let show = e.currentTarget.dataset.tag
    if (show) {
      this.setData({
        show
      })
    }
  },
    // 点击切换样式 获取日期
    chooseBac(e) {
      console.log(e);
      this.date = e.currentTarget.dataset.time //获取选择的日期
      this.day = e.currentTarget.dataset.day //获取周几
      let activeIndex = e.currentTarget.dataset.index;
      this.setData({
        activeIndex
      })
    },
  // 点击场地
  clickNormal(e) {
    this.fiel = e.currentTarget.dataset.fiel
    let fieldIndex = e.currentTarget.dataset.index
    this.setData({
      fieldIndex
    })
  },
  // 点击时间
  clickTime(e) {
    let timeIndex = e.currentTarget.dataset.index
    this.time  = e.currentTarget.dataset.time
    this.setData({
      timeIndex
    })
  },
  onDisplay() {
    this.setData({ show: true });
  },
  onClose() {
    this.setData({ show: false });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getMonth() + 1}/${date.getDate()}`;
  },
  // 选好时间点击确定
  onConfirm(event) {
    const [start, end] = event.detail;
    this.setData({
      show: false,
      date: `${this.formatDate(start)} - ${this.formatDate(end)}`,
    });
    console.log(event);
  },

})